home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / timedate.py < prev    next >
Text File  |  2009-10-09  |  3KB  |  106 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  19. #
  20. # Author: Don Welch
  21. #
  22.  
  23. __version__ = '2.0'
  24. __mod__ = 'hp-timedate'
  25. __title__ = 'Time/Date Utility'
  26. __doc__ = "Set the time and date on an HP Officejet all-in-one device using the PC time and date."
  27.  
  28. # Std Lib
  29. import sys
  30. import re
  31. import getopt
  32. import struct
  33. import operator
  34. import os
  35.  
  36. # Local
  37. from base.g import *
  38. from base.codes import *
  39. from base import device, status, utils, pml, tui, module
  40. from prnt import cups
  41.  
  42. try:
  43.     from fax import faxdevice
  44. except ImportError:
  45.     log.error("Unable to load fax services for HPLIP (required for hp-timedate). Exiting.")
  46.     sys.exit(1)
  47.  
  48.  
  49. PML_ERROR_CODES = {
  50.     pml.ERROR_OK_END_OF_SUPPORTED_OBJECTS: "OK: End of supported objects",
  51.     pml.ERROR_OK_NEAREST_LEGAL_VALUE_SUBSITUTED: "OK: Nearest legal value substituted",
  52.     pml.ERROR_UNKNOWN_REQUEST: "Unknown request",
  53.     pml.ERROR_BUFFER_OVERFLOW: "Buffer overflow",
  54.     pml.ERROR_COMMAND_EXECUTION: "Command execution",
  55.     pml.ERROR_UNKNOWN_OID: "Unknown OID",
  56.     pml.ERROR_OBJ_DOES_NOT_SUPPORT_SPECIFIED_ACTION: "Object does not support action",
  57.     pml.ERROR_INVALID_OR_UNSUPPORTED_VALUE: "Invalid or unsupported value",
  58.     pml.ERROR_PAST_END_OF_SUPPORTED_OBJS: "Past end of supported objects",
  59.     pml.ERROR_ACTION_CANNOT_BE_PERFORMED_NOW: "Action cannot be performed now",
  60.     pml.ERROR_SYNTAX: "Syntax",
  61. }
  62.  
  63. try:
  64.     mod = module.Module(__mod__, __title__, __version__, __doc__, None,
  65.                         (INTERACTIVE_MODE,))
  66.  
  67.     mod.setUsage(module.USAGE_FLAG_DEVICE_ARGS)
  68.  
  69.     opts, device_uri, printer_name, mode, ui_toolkit, lang = \
  70.         mod.parseStdOpts()
  71.  
  72.     device_uri = mod.getDeviceUri(device_uri, printer_name,
  73.         filter={'fax-type': (operator.gt, 0)},
  74.         back_end_filter=['hpfax'])
  75.  
  76.     try:
  77.         d = faxdevice.FaxDevice(device_uri, printer_name, disable_dbus=True)
  78.     except Error, e:
  79.         if e.opt == ERROR_DEVICE_DOES_NOT_SUPPORT_OPERATION:
  80.             log.error("Device does not support setting time/date.")
  81.             sys.exit(1)
  82.         else:
  83.             log.error(e.msg)
  84.             sys.exit(1)
  85.  
  86.     try:
  87.         try:
  88.             d.open()
  89.         except Error:
  90.             log.error("Unable to open device. Exiting. ")
  91.             sys.exit(1)
  92.  
  93.         try:
  94.             log.info("Setting time and date on %s" % device_uri)
  95.             d.setDateAndTime()
  96.         except Error:
  97.             log.error("An error occured!")
  98.     finally:
  99.         d.close()
  100.  
  101. except KeyboardInterrupt:
  102.     log.error("User exit")
  103.  
  104. log.info("")
  105. log.info('Done.')
  106.